home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / comm / amiex / news2ae.rexx < prev    next >
OS/2 REXX Batch file  |  1995-09-17  |  18KB  |  540 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  news 2 AmiExpress v0.9                                                   */
  4. /*                                                                           */
  5. /* Convert news messages into AmiExpress messages                            */
  6. /* I use this tool because I get the the news using AMiTCP and plink and just*/
  7. /* wanted to somehow convert them into my AmiExpress message base. Well it   */
  8. /* works just fine. REMEMBER make sure you backup your message base when you */
  9. /* test this. Sometime ago AE had a different messsage base structure and it */
  10. /* might not work for you if you have older ver of AE. But anyway it works   */
  11. /* just fine. If you have problems of any type please email me at:           */
  12. /* falco@falco.escape.com, ftp to falco.escape.com or telnet to it.          */
  13. /* Also you can call my bbs at 718-318-8315, have fun and l8r. If you have   */
  14. /* any comments or problems or whatever feel free to email me. This tool was */
  15. /* done in 30 mins so it might be not perfect but for me it does what it had */
  16. /* to do and I am happy. I might add some more stuff to it but who knows. l8r*/
  17. /*                                                                           */
  18. /*****************************************************************************/
  19.  
  20. CALL TIME('R')
  21.  
  22. addlib('rexxsupport.library',0,-30)
  23.  
  24. dir        = "Confs:Conf019/"
  25. UUNewsFalco    = "uunews:comp/sys/amiga/marketplace/"
  26. MessyType    = "P"
  27. ToWhom        = "All"
  28.  
  29. /*****************************************************************************/
  30. /*****************************************************************************/
  31. /*  Known bugs:                                                              */
  32. /*                                                                           */
  33. /*   - None                                                                  */
  34. /*                                                                           */
  35. /*****************************************************************************/
  36. /*****************************************************************************/
  37.  
  38. say ""
  39. say CENTER("News2AmiExpress v1.0",70)
  40. say ""
  41. say CENTER("Copyright © 1995 by Kool Falco",70)
  42. say CENTER("All rights reserved",70)
  43. say ""
  44.  
  45. /*say dir*/
  46. /*say UUNewsFalco*/
  47.  
  48. if EXISTS(UUNewsFalco||".next") then do
  49.                                  call open MyFile,(UUNewsFalco||".next"),'R'
  50.                                    NumberOfMessages = readln(MyFile)
  51.                                    NumberOfMessages = NumberOfMessages - 1
  52. say NumberOfMessages||" new messages found..."
  53.                                  CLOSE(MyFile)
  54.                                end
  55. else do
  56.        say ""
  57.        say "ERROR: Cannot find "||UUNewsFalco||".next file."
  58.        say ""
  59.        SAY 'Elapsed time='TIME('E')' seconds.'
  60.        Exit
  61.      end
  62.  
  63.  
  64. i = 1      /*************** USE THIS ONE *****************/
  65.  
  66. /*i = 13*/                              /**** TEMPORARY ****/
  67. /*do while (i <= 2)*/                   /**** TEMPORARY ****/
  68.  
  69. do while (i <= NumberOfMessages) /**********USE THIS LINE************/
  70.   if EXISTS(UUNewsFalco||i) then do
  71.                                    say "######## N E W  Message ########"
  72.  
  73.                                    call open MyTmpMsg,("ram:tmp.msg"),'W'
  74.  
  75.                                    say "working on message # ==> "||i
  76.                                    /* Reset those stats b4 each message. Then */
  77.                                    /* if those values are not = to "" then    */
  78.                                    /* the value is already read and dont have */
  79.                                    /* to read it again.                       */
  80.                                    MessageFrom        = ""
  81.                                    MessageSubject    = ""
  82.                                    MessageDate        = ""
  83.                                    MessageToEmail    = ""    /* Put this to comment of a message and then use to reply to it. */
  84.                                    FirstEmptyLine    = "NO"
  85.                                    MessageFromEmail     = ""
  86.  
  87. call open MyFile,(UUNewsFalco||i),'R'
  88.   do while ~EOF(MyFile)
  89.  
  90.     WholeLine = readln(MyFile)
  91.  
  92.     /*Subject: WTB: ZIP 256k RAM (PM) a3000*/
  93.     if (POS("Subject: ",WholeLine) = 1    & MessageSubject = "") then
  94.       do
  95.         MessageSubject = SUBSTR(WholeLine, 10)
  96.       end
  97.  
  98.     /*Date: 12 Sep 1995 00:37:37 -0400    */
  99.     /*Date: Sun, 10 Sep 95 09:56:30 -0500 */
  100.     if (POS("Date: ",WholeLine) = 1    & MessageDate = "") then
  101.       do
  102.         if DATATYPE(WORD(WholeLine,2),N) then
  103.           do
  104.             Day        = WORD(WholeLine,2)
  105.             Month    = WORD(WholeLine,3)
  106.             Year    = WORD(WholeLine,4)
  107.             TimeOfMessy    = WORD(WholeLine,5)
  108.           end
  109.         else
  110.           do
  111.             Day        = WORD(WholeLine,3)
  112.             Month    = WORD(WholeLine,4)
  113.             Year    = WORD(WholeLine,5)
  114.             TimeOfMessy    = WORD(WholeLine,6)
  115.           end
  116.         if LENGTH(Day) = 1 then Day = "0"||Day
  117.  
  118.         if    Month = "Jan" then Month = 01
  119.         else if Month = "Feb" then Month = 02
  120.         else if Month = "Mar" then Month = 03
  121.         else if Month = "Apr" then Month = 04
  122.         else if Month = "May" then Month = 05
  123.         else if Month = "Jun" then Month = 06
  124.         else if Month = "Jul" then Month = 07
  125.         else if Month = "Aug" then Month = 08
  126.         else if Month = "Sep" then Month = 09
  127.         else if Month = "Oct" then Month = 10
  128.         else if Month = "Nov" then Month = 11
  129.         else    Month = "Dec" then Month = 12
  130.  
  131.         if LENGTH(Year) = 2 then Year = "19"||Year
  132.  
  133.         ourdate = (((date('i',year||month||day,'s') + 2922) * 86400) + 21600)
  134.  
  135.         hour    = SUBSTR(TimeOfMessy, 1, 2)
  136.         hour    = STRIP(hour, L, "0")
  137.         if hour = "" then hour = 0
  138.         minute  = SUBSTR(TimeOfMessy, 4, 2)
  139.         minute  = STRIP(minute, L, "0")
  140.         if minute = "" then minute = 0
  141.         seconds = SUBSTR(TimeOfMessy, 7, 2)
  142.         seconds = STRIP(seconds, L, "0")
  143.         if seconds = "" then seconds = 0
  144.  
  145.         TimeOfMessy = (hour * 60 * 60) + (minute * 60) + seconds
  146.  
  147.         MessageDate = ourdate + TimeOfMessy
  148.  
  149.         /*say WholeLine*/
  150.  
  151.       end
  152.  
  153.     if (POS("From: ",WholeLine) = 1    & MessageFrom = "") then
  154.       do
  155.  
  156.         MessageFromEmail = SUBSTR(WholeLine, 7)
  157.  
  158.         if ((POS("(",WholeLine) = 0) & (POS("<",WholeLine) = 0)) then
  159.           do
  160.             MessageFrom = "Anonymous"
  161.           end
  162.         /*From: Nick Plante <nplante@delphi.com>*/
  163.         else if ((POS("(",WholeLine) = 0) & (POS(")",WholeLine) = 0)) then
  164.           do
  165.             MessageFrom = SUBSTR(WholeLine, 7, INDEX(WholeLine,"<") - 8)
  166.           end
  167.         /*From: bilboyce@iconz.co.nz (Bill Boyce)*/
  168.         else
  169.           do
  170.             a = INDEX(WholeLine,"(")
  171.             b = INDEX(WholeLine,")")
  172.             MessageFrom = SUBSTR(WholeLine, a + 1, (b - a) - 1)
  173.           end
  174.       end
  175.  
  176.     /*Reply-To: dally28@aol.com (Dally28)*/
  177.     if (POS("Reply-To: ",WholeLine) = 1    & MessageToEmail = "") then
  178.       do
  179.             MessageToEmail = SUBSTR(WholeLine, 11)
  180.       end
  181.  
  182.  
  183.     if WholeLine = "" & FirstEmptyLine = "NO" then
  184.       do
  185.         FirstEmptyLine = "YES"
  186.         if MessageToEmail = "" then MessageToEmail = MessageFromEmail
  187.  
  188.         say "From     : ==>"||MessageFrom||"<=="
  189.         say "FromEmail: ==>"||MessageFromEmail||"<=="
  190.         say "ToEmail  : ==>"||MessageToEmail||"<== **********************"
  191.         say "Date     : ==>"||MessageDate||"<=="
  192.         say "Subject  : ==>"||MessageSubject||"<=="
  193.  
  194.       end
  195.  
  196.     /* if this then write message */
  197.     if FirstEmptyLine = "YES" then writeln(MyTmpMsg,WholeLine)
  198.  
  199.   end
  200. CLOSE(MyFile)
  201. Close(MyTmpMsg)
  202.  
  203. call AddMessageFullFunction
  204. ADDRESS COMMAND "delete ram:tmp.msg"
  205.  
  206. /*
  207. say "#### Message STARTS HERE ####"
  208. ADDRESS COMMAND "type ram:tmp.msg"
  209. say "#### Message STOPS  HERE ####"
  210. */
  211.  
  212.  
  213.                                  end
  214.   else say "message # ==> "||i||" not found."
  215.   i = i + 1
  216. end
  217.  
  218. say "Finished."
  219. say ""
  220.  
  221. SAY 'Elapsed time='TIME('E')' seconds.'
  222. Exit
  223.  
  224. /*******************************************************************************/
  225. /*******************************************************************************/
  226. /*******************************************************************************/
  227. /*******************************************************************************/
  228. /*******************************************************************************/
  229. /*******************************************************************************/
  230. /*******************************************************************************/
  231. /*******************************************************************************/
  232. /*******************************************************************************/
  233. /*******************************************************************************/
  234. /*******************************************************************************/
  235. /*******************************************************************************/
  236. /*******************************************************************************/
  237. /*******************************************************************************/
  238. /*******************************************************************************/
  239. /*******************************************************************************/
  240. /*******************************************************************************/
  241. /*******************************************************************************/
  242. /*******************************************************************************/
  243. /*******************************************************************************/
  244. /*******************************************************************************/
  245. /*******************************************************************************/
  246. /*******************************************************************************/
  247. /*******************************************************************************/
  248. /*******************************************************************************/
  249. /*******************************************************************************/
  250. /*******************************************************************************/
  251. /*******************************************************************************/
  252. /*******************************************************************************/
  253. /*******************************************************************************/
  254. /*******************************************************************************/
  255. /*******************************************************************************/
  256. /*******************************************************************************/
  257. /*******************************************************************************/
  258. /*******************************************************************************/
  259. /*******************************************************************************/
  260. /*******************************************************************************/
  261. /*******************************************************************************/
  262. /*******************************************************************************/
  263. /*******************************************************************************/
  264. /*******************************************************************************/
  265. /*******************************************************************************/
  266. /*******************************************************************************/
  267. /*******************************************************************************/
  268.  
  269.  k = 0
  270.  j = 0
  271.  ok = "NO"
  272.  firstmsg = "YES"
  273.  
  274.  if EXISTS("ram:temp.msg") then ADDRESS COMMAND "delete ram:temp.msg"
  275.  
  276. /* say UUNewsFalco */
  277.  call open MailHeaderFile,(UUNewsFalco),'R'
  278.   do while ~EOF(MailHeaderFile)
  279.     Message = readln(MailHeaderFile)
  280.     n = POS("From !",Message)
  281.     if n = 1 then do
  282.  
  283.                     if EXISTS("ram:temp.msg") then do
  284.                                                      CLOSE(TempMsgBody)
  285.                                                    end
  286.  
  287. if firstmsg = "NO" then call DoTheMessage
  288.  
  289.  
  290.                     m = POS("From !owner-amiga",Message)
  291.                     if m = 1 then ok = "YES"
  292.                     else ok = "NO"
  293.                     k = k + 1 /* how many messages found */
  294.                     j = 1
  295.  
  296.                     say "########################### NEW MESSAGE ###########################"
  297. firstmsg = "NO"
  298.  
  299.  
  300.  
  301.                     call open TempMsgBody,("ram:temp.msg"),'W'
  302.  
  303.  
  304.  
  305.                   end
  306.     n = POS("From: ",Message)
  307.     if n = 1 then do
  308.                     MessageIsFrom = SUBSTR(Message, 7, (POS("<",Message,8) - 1) - 7)
  309.                     say "From    : ==>"||MessageIsFrom||"<=="
  310.                   end
  311.     n = POS("Subject: ",Message)
  312.     if n = 1 then do
  313.                     MessageSubjectIs = SUBSTR(Message, 10)
  314.                     say "Subject : ==>"||MessageSubjectIs||"<=="
  315.                   end
  316.     n = POS("Date: ",Message)
  317.     if n = 1 then do
  318.                     Day   = WORD(Message,3)
  319.                      if LENGTH(Day) = 1 then Day = "0"||day
  320.                     Month = WORD(Message,4)
  321.                      if Month = "Jan" then Month = 01
  322.                      if Month = "Feb" then Month = 02
  323.                      if Month = "Mar" then Month = 03
  324.                      if Month = "Apr" then Month = 04
  325.                      if Month = "May" then Month = 05
  326.                      if Month = "Jun" then Month = 06
  327.                      if Month = "Jul" then Month = 07
  328.                      if Month = "Aug" then Month = 08
  329.                      if Month = "Sep" then Month = 09
  330.                      if Month = "Oct" then Month = 10
  331.                      if Month = "Nov" then Month = 11
  332.                      if Month = "Dec" then Month = 12
  333.                     Year  = WORD(Message,5)
  334.  
  335.                     ourdate = (((date('i',year||month||day,'s') + 2922) * 86400) + 21600)
  336.  
  337.                     TimeOfMessy = WORD(Message,6)
  338.                     hour    = SUBSTR(TimeOfMessy, 1, 2)
  339.                     hour    = STRIP(hour, L, "0")
  340.                     if hour = "" then hour = 0
  341.                     minute  = SUBSTR(TimeOfMessy, 4, 2)
  342.                     minute  = STRIP(minute, L, "0")
  343.                     if minute = "" then minute = 0
  344.                     seconds = SUBSTR(TimeOfMessy, 7, 2)
  345.                     seconds = STRIP(seconds, L, "0")
  346.                     if seconds = "" then seconds = 0
  347.  
  348.                     TimeOfMessy = (hour * 60 * 60) + (minute * 60) + seconds
  349.  
  350.                     MessageDateIs = ourdate + TimeOfMessy
  351.                   end
  352.  
  353.     n = POS(" ",Message)
  354.     if (n = 0) & (j = 1) then j = 0
  355.  
  356. /*******=======>>>>>>>>>>>>>>>    if j = 0 then say Message */
  357.     if j = 0 & ok = "YES" then do
  358. /*                                 say Message*/
  359.  
  360.     writeln(TempMsgBody,Message)
  361.  
  362.  
  363. /*####################################################################
  364. ######################################################################
  365. ######################################################################
  366. ####################################################################*/
  367.  
  368.                                end
  369. end
  370.  
  371. call DoTheMessage
  372.  
  373. say k||" <=== messages found"
  374. call close(MailHeaderFile)
  375.  
  376.  
  377. SAY 'Elapsed time='TIME('E')' seconds.'
  378. Exit
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389. DoTheMessage:
  390. if EXISTS("ram:temp.msg") then do
  391.                                  CLOSE(TempMsgBody)
  392.                                end
  393.   if ok = "YES" then do
  394. /*
  395.                        say "FromWhom = "||SUBSTR(MessageIsFrom,1,30)
  396.                        say "MessySubject = "||SUBSTR(MessageSubjectIs,1,30)
  397.                        say "DateMessySend = "||d2c(MessageDateIs)
  398. */
  399.                        call AddMessageFullFunction
  400.                      end
  401.  
  402. /*                    ADDRESS COMMAND "Type ram:temp.msg"*/
  403.  
  404. /*if EXISTS("ram:temp.msg") then if ok = "YES" then call AddMessageFullFunction*/
  405. /* ADDRESS COMMAND "Type ram:temp.msg" */
  406.  
  407.  
  408.   ADDRESS COMMAND "delete ram:temp.msg"
  409.  
  410. return
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430. AddMessageFullFunction:
  431.  
  432. /*
  433.  MessageFrom        = ""
  434.  MessageSubject        = ""
  435.  MessageDate        = ""
  436.  MessageToEmail        = ""    /* Put this to comment of a message and then use to reply to it. */
  437.  FirstEmptyLine        = "NO"
  438.  MessageFromEmail    = ""
  439. */
  440.  
  441. MessyType = "P"
  442. ToWhom   = 'All'
  443. FromWhom = SUBSTR(MessageFrom,1,30)
  444. MessySubject = SUBSTR(MessageSubject,1,30)
  445. /*say MessageDateIs*/
  446. DateMessySend = d2c(MessageDate)
  447.  
  448.  
  449.  
  450.   if ~exists(dir||'MsgBase/HeaderFile') then
  451.     do
  452.       call open fes, (dir||'MsgBase/HeaderFile'), 'W'
  453.       close(fes)
  454.     end
  455.  
  456.   st = STATEF(dir||'MsgBase/HeaderFile')
  457.   parse var st type size blk bits day min tick com
  458.   num=size/110+1
  459.   numero=d2c(num)
  460.   call numm
  461.  
  462.   cozza = ToWhom
  463.   clen=31
  464.   call add0
  465.   unome=cozza
  466.   cozza=FromWhom
  467.   call add0
  468.   chi=cozza
  469.   clen=32
  470.   cozza=MessySubject
  471.   call add0
  472.   motivo=cozza
  473.   ora = DateMessySend
  474.   txt=MessyType||'0'x||numero||unome||chi||motivo||ora||'0'x||'0'x||'0'x||'0'x||'0'x||'0'x
  475.   numero=d2c(num+1)
  476.   call numm
  477.   txt1='00000001'x||numero||'00000001000000000000'x
  478.   call open fes, (dir||'MsgBase/HeaderFile'), 'A'
  479.     writech(fes,txt)
  480.   close(fes)
  481.   call open fes, (dir||'MsgBase/MailStats'), 'W'
  482.     writech(fes,txt1)
  483.   close(fes)
  484. /*
  485.   call open fes, (dir||'MsgBase/'||num), 'W'
  486.  
  487.       writeln(fes,'this is a test of the message adder')
  488.  
  489.   close(fes)
  490. */
  491.  
  492.   cmd2exe = 'copy ram:tmp.msg '||dir||'MsgBase/'||num
  493.   ADDRESS COMMAND cmd2exe
  494.  
  495. /********** MAKE COMMENTS ***********/
  496. /* Doesnt work since BBS thinks we are attaching a file to it. */
  497. /*
  498.   MessageToEmail = '"     '||MessageToEmail||'"'
  499.   cmd2exe = 'Filenote '||dir||'MsgBase/'||num||' '||MessageToEmail
  500.   ADDRESS COMMAND cmd2exe
  501. */
  502.  
  503.   if ~exists(dir||'MsgBase/MailLock') then
  504.     do
  505.       call open fes, (dir||'MsgBase/MailLock'), 'W'
  506.       writech(fes,'DO NOT DELETE!'||'a'x)
  507.       close(fes)
  508.     end
  509.   say "Message Number "||num||"...done!"
  510.   tr
  511.  
  512. return
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519. exit:
  520.   tr
  521.   exit
  522.  
  523.  
  524. add0:
  525.   len=length(cozza)
  526.   do while len~=clen
  527.     cozza=cozza||'0'x
  528.     len=length(cozza)
  529.   end
  530. return
  531.  
  532.  
  533. numm:
  534.   len=length(numero)
  535.   do while len~=4
  536.     numero='0'x||numero
  537.     len=length(numero)
  538.   end
  539.  
  540.